import React, { Component } from "react";

export default function loadComponents(importComponent) {
	class LoadComponents extends Component {
		constructor(props) {
			super(props);

			this.state = {
				component: null
			};
		}

		async componentDidMount() {
			const { default: component } = await importComponent();
			console.log(`加载页面。。。`)
			this.setState({
				component: component
			});
		}

		render() {
			const C = this.state.component;

			return C ? <C {...this.props} /> : null;
		}
	}

	return LoadComponents;
}